-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: vaults fuzzing #918
base: feat/vaults
Are you sure you want to change the base?
test: vaults fuzzing #918
Conversation
Hardhat Unit Tests Coverage Summary
Diff against master
Results for commit: 7d05ee2 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start!
Some suggestions and comments left.
Also, looks like it need to me merged with vaults branch once again, because some tests are failing.
import {StdUtils} from "forge-std/StdUtils.sol"; | ||
import {Vm} from "forge-std/Vm.sol"; | ||
import {console2} from "forge-std/console2.sol"; | ||
import {Protocol__Deployment, ILido} from "./Protocol__Deployment.t.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better naming is Protocol__Context so as to put methods related to the protocol interactions later, e.g., adding / removing permissions, impersonating agents, etc...
1d41029
to
7d05ee2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No major issues, at least for now, need to validate boundaries and maybe add more invariants.
|
||
// 0.002792 * 10^18 | ||
// 0.0073 * 10^18 | ||
uint256 constant maxYiedPerOperatorWei = 2_792_000_000_000_000; // which % of slashing could be? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint256 constant maxYiedPerOperatorWei = 2_792_000_000_000_000; // which % of slashing could be? | |
uint256 constant maxYieldPerOperatorWei = 2_792_000_000_000_000; // which % of slashing could be? |
?
// for testing purposes only | ||
pragma solidity ^0.8.0; | ||
|
||
import "foundry/lib/forge-std/src/Vm.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import "foundry/lib/forge-std/src/Vm.sol"; |
Already present below
import {StdCheats} from "forge-std/StdCheats.sol"; | ||
import {StdUtils} from "forge-std/StdUtils.sol"; | ||
import {Vm} from "forge-std/Vm.sol"; | ||
import {console2} from "../../foundry/lib/forge-std/src/console2.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import {console2} from "../../foundry/lib/forge-std/src/console2.sol"; | |
import {console2} from "forge-std/console2.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to put it into test/0.8.25/contracts and rename it like SecondOpinionOracle__MockForAccountingFuzzing
@@ -3,8 +3,11 @@ | |||
|
|||
pragma solidity 0.8.9; | |||
|
|||
import {StakingRouter} from "contracts/0.8.9/StakingRouter.sol"; | |||
|
|||
contract StakingRouter__MockForLidoAccounting { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed that this file is being used in the accounting unit tests. It would be better to clone the file and rename it to StakingRouter__MockForLidoAccountingFuzzing to clarify its purpose. Separating the mocks will simplify mock management and ensure that they do not interfere with other tests.
* forge-config: default.invariant.depth = 256 | ||
* forge-config: default.invariant.fail-on-revert = true | ||
*/ | ||
function invariant_totalShares() public view { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Maybe add an invariant that lido.getExternalShares = startExternalBalance + mintedExternal - burnedExternal? So we'll know it something is odd inside a math for external shares?
// if (_report.timestamp >= block.timestamp) revert IncorrectReportTimestamp(_report.timestamp, block.timestamp); | ||
vm.warp(_timestamp + 1); | ||
|
||
fuzz._lidoExecutionLayerRewardVaultWei = bound(fuzz._lidoExecutionLayerRewardVaultWei, 0, 1_000) * 1 ether; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing comments on why the bounding appears as it does would be helpful during reviews and test updates.
|
||
function handleOracleReport(FuzzValues memory fuzz) external { | ||
uint256 _timeElapsed = 86_400; | ||
uint256 _timestamp = 1_737_366_566 + _timeElapsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a specific timestamp? Can block.timestamp be used?
} | ||
|
||
contract AccountingHandler is CommonBase, StdCheats, StdUtils { | ||
struct Ghost { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Maybe add a boundary holder to track minimum and maximum values used in all the runs, so we can review them after the test and ensure we're not missing any potential values chunks?
|
||
pragma solidity 0.8.9; | ||
|
||
contract SecondOpinionOracle__Mock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that we need that mock. We can harness OracleReportSanityChecker and just return true on _askSecondOpinion.
Test shareRate with fuzzing